<template>
  <div class="fruit">
    <h1>{{ fruit.name }}</h1>
    <p>{{ fruit.description }}</p>
  </div>
</template>

<script>
import fruits from '@/assets/fruits.json'

export default {
  name: 'FruitView',
  data() {
    return {
      fruit: {}
    }
  },
  created() {
    this.fetchFruitData()
  },
  watch: {
    '$route.params.id': 'fetchFruitData'
  },
  methods: {
    fetchFruitData() {
      const fruitId = this.$route.params.id
      console.log('Fruit ID:', fruitId) // Debug statement to check the fruit ID
      console.log('Fruits Data:', fruits) // Debug statement to check the fruits data
      this.fruit = fruits.find(fruit => fruit.id === fruitId) || {}
      console.log('Selected Fruit Data:', this.fruit) // Debug statement to check the selected fruit data
    }
  }
}
</script>

<style scoped>
h1 {
  margin: 20px 0;
}
p {
  font-size: 18px;
}
</style>